package com.ruoyi.statisticalCenter.controller;

import java.util.List;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.logistic.domain.PageInfo;
import com.ruoyi.statisticalCenter.domain.vo.ScSheetRechargeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.statisticalCenter.domain.ScSheetRecharge;
import com.ruoyi.statisticalCenter.service.IScSheetRechargeService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;

/**
 * 面单充值Controller
 *
 * @author pyx
 * @date 2024-03-01
 */
@RestController
@RequestMapping("/sc/recharge")
@Api(tags = "统计中心-面单充值")
public class ScSheetRechargeController extends BaseController {
    @Autowired
    private IScSheetRechargeService scSheetRechargeService;

    /**
     * 查询面单充值列表
     */
    @PostMapping("/list")
    @ApiOperation("查询面单充值列表")
    public R list(@RequestBody ScSheetRechargeVo scSheetRechargeVo) {
        if (StringUtils.isNotBlank(scSheetRechargeVo.getObjectType())){
            if (scSheetRechargeVo.getObjectType().equals("contractArea")){
                scSheetRechargeVo.setObjectType("承包区");
            }else{
                scSheetRechargeVo.setObjectType("客户");
            }
        }
        if (StringUtils.isNotBlank(scSheetRechargeVo.getIssueSource())){
            if (scSheetRechargeVo.getIssueSource().equals("network")){
                scSheetRechargeVo.setIssueSource("网店管家");
            }else{
                scSheetRechargeVo.setIssueSource("移动端");
            }
        }
        List<ScSheetRecharge> list = scSheetRechargeService.selectScSheetRechargeList(scSheetRechargeVo);
        if (list == null || list.size() == 0) {
            return R.ok("暂无数据");
        } else {
            return R.ok(PageInfo.info(list));
        }
    }

    /**
     * 新增面单充值
     */
    @PostMapping("/add")
    @ApiOperation("新增面单充值")
    public R addSave(@RequestBody ScSheetRecharge scSheetRecharge) {
        return scSheetRechargeService.insertScSheetRecharge(scSheetRecharge) > 0 ? R.ok("新增成功") : R.fail("新增失败");
    }

    /**
     * 修改保存面单充值
     */
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ScSheetRecharge scSheetRecharge) {
        return toAjax(scSheetRechargeService.updateScSheetRecharge(scSheetRecharge));
    }

    /**
     * 删除面单充值
     */
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(scSheetRechargeService.deleteScSheetRechargeByIds(ids));
    }
}
